package cc.booku.owlbox.VideoPlayer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListAdapter;
import android.widget.TextView;


import java.util.ArrayList;

import cc.booku.owlbox.R;

public class TVSeries_A extends BaseAdapter implements ListAdapter {


    private ArrayList<TVSeries_C> tvSeries_cs;
    private int id;
    private Context context;
    private LayoutInflater inflater;

    public TVSeries_A(int gather_item, Context context, ArrayList<TVSeries_C> tvSeries_cs) {
        this.tvSeries_cs = tvSeries_cs;
        this.context = context;
        this.id = gather_item;
        inflater = LayoutInflater.from(context);

    }

    @Override
    public int getCount() {
        return tvSeries_cs.size();
    }

    @Override
    public Object getItem(int i) {
        return tvSeries_cs.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @SuppressLint("WrongConstant")
    @Override

    public View getView(int i, View view, ViewGroup viewGroup) {

        TextView tv_series = null;
        TextView tv_url = null;
        ViewHolder viewHolder;
        if (view == null) {
            view = inflater.inflate(id, null);
            tv_series = (TextView) view.findViewById(R.id.tv_series);
            tv_url = (TextView) view.findViewById(R.id.tv_url);
            view.setTag(new ViewHolder(tv_series, tv_url));
        } else {
            ViewHolder viewHolder1 = (ViewHolder) view.getTag(); // 重新获取ViewHolder
            tv_series = viewHolder1.tv_series;
            tv_url = viewHolder1.tv_url;
        }
        TVSeries_C tvSeries_c = (TVSeries_C) tvSeries_cs.get(i); // 获取当前项的实例

        tv_url.setText(tvSeries_c.getTVUrl().toString());//对象为空
        tv_series.setText(tvSeries_c.getTVSeries().toString());

        return view;

    }


    private final class ViewHolder {
        TextView tv_url = null;
        TextView tv_series = null;


        public ViewHolder(TextView tv_series, TextView tv_url) {
            this.tv_url = tv_url;
            this.tv_series = tv_series;
        }

    }
}